﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_CM_GetContactByStaff]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_CM_GetContactByStaff];
GO
CREATE PROCEDURE [dbo].[sproc_CM_GetContactByStaff]
@staffid int,
@begintime datetime,
@endtime datetime

AS

    IF(@begintime='1900-1-1' and @endtime='1900-1-1')
    BEGIN
        SELECT * FROM UDS_CM_ClientContact 
        WHERE MarketmanID=@staffid
    END
    ELSE
    BEGIN
        SELECT * FROM UDS_CM_ClientContact
        WHERE MarketmanID=@staffid and UpdateTime between @begintime and Dateadd(d,1,@endtime)
    END